 # 导包
import unittest, requests
import xlrd,re
from api.getpath import GetTestDataPath
from scripts.TestRequest import TestPostRequestCookie
#创建继承unittest.TestCase的类
testdata = xlrd.open_workbook(GetTestDataPath())

def lagou_denglu():
        url_verify = "http://localhost/index.php?m=Home&c=User&a=verify&r=0.9698092918823165"
         # 登录的URL
        url_login = "http://localhost/index.php?m=Home&c=User&a=do_login&t=0.8916582864091132"
        # print(requests.get(url_verify).cookies)
        cookies = requests.get(url_verify).cookies

        response = requests.post(url=url_login,
                                 data={"username": "13800138006", "password": "123456", "verify_code": "8888"},
                                 headers={"Content-Type": "application/x-www-form-urlencoded"},
                                 cookies=cookies)
        # 打印登录的结果
        # print(response.json())
        try:
            testcaseid = "1-1"
            testname = "拉钩登录" + testcaseid
            testhope=response.json().get("msg")
            # print(testhope)
            fanhuitesthpe=response.json().get("msg")
            # print(fanhuitesthpe)
            hdata = {"username": "13800138006", "password": "123456", "verify_code": "8888"}

            header = {"Content-Type": "application/x-www-form-urlencoded"}
            cookies = requests.get(url_verify).cookies
            r = TestPostRequestCookie(url_login, hdata,header,testcaseid, testname, testhope,
                                fanhuitesthpe,cookies,"msg")
            # print(r)
        except Exception as e:
            print(e)

# lagou_denglu()